package com.wxpay.demo.utils;


import java.util.Random;
import java.util.UUID;

public class IdUtils {

    /**
     * 生成随机数作为主键Id
     * @param length
     * @return
     */
    public static long generateRandom(int length) {
        Random random = new Random();
        char[] digits = new char[length];
        digits[0] = (char) (random.nextInt(9) + '1');
        for (int i = 1; i < length; i++) {
            digits[i] = (char) (random.nextInt(10) + '0');
        }
        return Long.parseLong(new String(digits));
    }

    public static void main(String[] args) {
        long id=generateRandom(18);
        System.out.println(id);
    }

    /**
     * 生成uuid
     *
     * @return
     */
    public static String geneUuid() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
}
